/**
 * @author taowei20061122@163.com
 *
 * 2013-6-10 上午05:54:12
 */
package study.designpattern.observer;


import study.designpattern.observer.impl.NewsPaper;
import study.designpattern.observer.impl.Reader;
import study.designpattern.observer.impl.Watcher;
import study.designpattern.observer.impl.WaterQuality;

/**
 * 
 * @author taowei20061122@163.com
 *
 * 2013-6-10 上午05:54:12
 */
public class Client {


	public static void main(String[] args) {
		// 创建一个报纸对象，作为被观察者
		NewsPaper newsPaper = new NewsPaper();		
		// 创建读者，也就是观察者
		Reader reader1 = new Reader();
		reader1.setName("张三");
		Reader reader2 = new Reader();
		reader2.setName("李四");		
		//注册阅读者
		newsPaper.attach(reader1);
		newsPaper.attach(reader2);		
		//要出报纸了
		newsPaper.setContent("本期的内容是观察者模式");
		
		
		//创建水质主题对象
		WaterQuality subject = new WaterQuality();
		//创建几个观察者
		WaterQualityObserver watcher1 = new Watcher();
		watcher1.setJob("监测员");
		WaterQualityObserver watcher2 = new Watcher();
		watcher2.setJob("预警人员");
		WaterQualityObserver watcher3 = new Watcher();
		watcher3.setJob("监测部门领导");
		//注册观察者
		subject.attach(watcher3);
		subject.attach(watcher2);
		subject.attach(watcher1);
		//填写水质报告
		System.out.println("当水质正常的时候---------");
		subject.setPolluteLevel(0);
		System.out.println("当水质轻度污染的时候---------");
		subject.setPolluteLevel(1);
		System.out.println("当水质中度污染的时候---------");
		subject.setPolluteLevel(2);
		

	}

}
